@extends('admin.layout')
@section('content')
            
      <!-- BEGIN MAIN CONTENT -->
      
      
      <section id="main-content">
             
    <!-- BEGIN WRAPPER  -->
        <section class="wrapper">
                     <section class="panel">
                        <header class="panel-heading">
                           <span class="label label-primary" id="addAttr"><b>添加商品根类型属性输入框</b></span>
                           <span class="label label-primary" id="delAttr"><b>删除商品根类型属性输入框</b></span>
                           <span class="tools pull-right">
                           <a href="javascript:;" class="fa fa-chevron-down"></a>
                           <a href="javascript:;" class="fa fa-times"></a>
                           </span>
                        </header>

                           
                         @if (count($errors) > 0)
                           <div class="box-body">
                              <div class="alert alert-danger alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="fa fa-warning"></i> 商品类型添加失败:</h4>
                        
                            
                                <ul>
                                    @foreach ($errors->all() as $error)
                                        <li>{{ $error }}</li>
                                    @endforeach
                                </ul>
                             </div>
                            </div><!-- /.box-body -->
                        @endif  

                        @if(session('info')) 

                            <div class="box-body">
                              <div class="alert alert-danger alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="fa fa-warning"></i> {{ session['info'] }}!</h4>
                        @endif          

                        <div class="panel-body" >
                           <form  action="/admin/type/doedit" method="post">
                            {{ csrf_field() }}
                              <div class="form-group">
                                 <label for="InputUsername">商品根类型名</label>
                                 <input type="hidden" name='id' value="{{ $data -> id }}">
                                 <input type="hidden" name='pid' value="{{ $data -> cate_pid }}">
                                 <input type="hidden" name='path' value="{{ $data -> cate_path }}">
                                 <input class="form-control" id="InputName" placeholder="请输入商品类型名" type="text" name="cate_name" value="{{ $data -> cate_name }}">

                                 @foreach($attrs_arr as $k => $v)
                                    
                                    <input class="minimal" type="checkbox" name="{{ 'name'.$k }}" checked="checked" value="{{ $k }}">{{ $v }}
                                 @endforeach
                              </div>  
                              <div class="form-group">
                                 
                                 <div id="pare">
                                    
                                 </div>
                              </div>                 
                              <button type="submit" class="btn btn-info">修改商品类型属性</button>
                           </form>
                        </div>
                     </section>
               </section>
    <!-- END WRAPPER  -->
      </section>
      <!-- END MAIN CONTENT -->

      <script type="text/javascript">
        // 获取添加属性输入框的元素
        var addAttr=document.getElementById('addAttr');
        // 获取删除元素输入框的元素
        var delAttr=document.getElementById('delAttr');

        var pare=document.getElementById('pare');

        var i=1;
        
        addAttr.onclick=function(){
          // alert('111');
          
          // 创建节点
          var inp=document.createElement('input');
          // 添加节点属性
          inp.setAttribute('class',"form-control");
          inp.setAttribute('placeholder',"请输入属性名称"+i);
          inp.setAttribute('type',"text");
          inp.setAttribute('name',"attr"+i);
          // 添加节点到父元素中
          pare.appendChild(inp);
          // 创建新的节点
          var br=document.createElement('br');
          // 添加节点到父元素中
          pare.appendChild(br);
          i++ ;
        }

        delAttr.onclick=function(){
          // alert('222');
          pare.removeChild(pare.lastElementChild);
          pare.removeChild(pare.lastElementChild);
          i--;
          if(i == 1) i=1;
          console.log(i);
        }
      </script>
           

@endsection